# requests不管是代理还是客户端验证都比urllib2简单太多

import requests

# (免费代理)根据协议类型，选择不同的代理
proxy_free = {
  "http": "http://12.34.56.79:9527",
  "https": "http://12.34.56.79:9527",
}

# (私密代理)如果代理需要使用HTTP Basic Auth，可以使用下面这种格式：
proxy_cost = { "http": "mr_mao_hacker:sffqry9r@61.158.163.130:16816" }

# web客户端验证
auth=('test', '123456')


# 代理:post还是get跟之前一样, 只不过参数多传个proxies
response1 = requests.get("http://www.baidu.com", proxies = proxy_free)
response2 = requests.get("http://www.baidu.com", proxies = proxy_cost)
# 验证:post还是get跟之前一样, 只不过参数多传个author
response3 = requests.get("http://www.baidu.com", auth = auth)

print(response1.text)
print(response2.text)
print(response3.text)
